package br.com.center.loja.ws.dto.converter;

import java.util.ArrayList;
import java.util.List;

import br.com.center.loja.model.City;
import br.com.center.loja.ws.dto.CityDTO;

public class CityDTOConverter implements Converter<City, CityDTO> {

	@Override
	public CityDTO to(City element) {
		CityDTO dto = new CityDTO();
		dto.setCode(element.getCode());
		
//		if(element.getMajor() != null){
//			dto.setMajor(to(element.getMajor()));
//		}
		
		dto.setName(element.getName());
		dto.setState(element.getState());
		dto.setTypeCity(element.getTypeCity());
		dto.setZipCode(element.getZipCode());
		
		return dto;
	}

	@Override
	public City from(CityDTO element) {
		City city = new City();
		city.setCode(element.getCode());
		city.setMajor(from(element.getMajor()));
		city.setName(element.getName());
		city.setState(element.getState());
		city.setTypeCity(element.getTypeCity());
		city.setZipCode(element.getZipCode());
		
		return city;
	}

	@Override
	public List<CityDTO> to(List<City> elements) {
		List<CityDTO> result = new ArrayList<CityDTO>();
		
		for(City element : elements){
			result.add(to(element));
		}
		
		return result;
	}

	@Override
	public List<City> from(List<CityDTO> elements) {
		List<City> result = new ArrayList<City>();
		
		for(CityDTO element : elements){
			result.add(from(element));
		}
		
		return result;
	}

}
